import ResultWrapper = require('../ResultWrapper')
import RequestResult = require("../RequestResult")
import RequestListResult = require("../RequestListResult")
import BaseModel = require('../BaseModel')
import Order = require('../model/Order')
//code1

//code1

/**
 * 下单
 */
class OrderApiAddOrder {
    
    get path(): string {
        return '/OrderApi/addOrder'
    }
    
    get isUpload(): boolean {
        return false
    }

    setup(app: any, path: string) {
        console.log('setup service: /' + path)
    }

    //POST
    create(data: any, params: any) {
        return this.doWork(data)
    }

    doWork(params: any): Promise<any> {

        /**顾客角色：0.普通散客[默认]，1.批发商顾客*/
        let buyer_role: number = params.buyer_role
        /**购买者手机号码*/
        let buyer_phone: string = params.buyer_phone
        /**购买者姓名*/
        let buyer_name: string = params.buyer_name
        /**取货方式（0.自提，1.配送至车，2.物流）*/
        let delivery_type: number = params.delivery_type
        /**送货地址*/
        let address: string = params.address
        /**备注*/
        let remark: string = params.remark
        /**产品对象json数组*/
        let products: string = params.products
        /**批发商标识*/
        let wholesaler_token: string = params.wholesaler_token


        let callback = (
            resolve: (data: RequestResult<Order>) => void, 
            reject: (error: Error) => void) => {

            let data = new Order()
            let result = ResultWrapper.wrap(data)
            result.message = '假数据'

//code2

//code2
            resolve(result)
        }
        return new Promise(callback)
    }
}

export = OrderApiAddOrder